﻿Imports System.Collections.ObjectModel

Public Class Data
    Private _FileCount As Integer
    Private _TypeCount As Integer
    Private _Size As Integer
    Private _FileTypes As New List(Of FileType)

    Public ReadOnly Property FileCount As Integer
        Get
            Return _FileCount
        End Get
    End Property

    Public ReadOnly Property TypeCount As Integer
        Get
            Return _TypeCount
        End Get
    End Property

    Public ReadOnly Property Size As Integer
        Get
            Return _Size
        End Get
    End Property

    Public ReadOnly Property FileTypes As ReadOnlyCollection(Of FileType)
        Get
            Return _FileTypes.AsReadOnly
        End Get
    End Property

    Public Sub addFile(ByVal fullPath As String, ByVal currentPath As String)
        Dim newFile As New File(fullPath, currentPath)
        Dim extension As String = getExtension(currentPath)
        _Size += newFile.Size

        For Each fileType As FileType In _FileTypes
            If fileType.Type = extension Then
                fileType.add(newFile)
                Exit Sub
            End If
        Next

        Dim newFileType As New FileType
        newFileType.Type = extension
        newFileType.add(newFile)
        _FileTypes.Add(newFileType)
        _TypeCount += 1
    End Sub

    Private Function getExtension(ByVal path As String) As String
        Dim extension As String = IO.Path.GetExtension(path)
        If extension = "" Then Return "NO-EXTENSION"
        Return extension
    End Function

    Public Sub report()
        For Each fileType As FileType In _FileTypes
            Debug.WriteLine(
                "File type " & fileType.Type & ", has " & fileType.Size & " bytes in " & fileType.GetCount & " files.")
        Next
    End Sub
End Class
